import datetime
import random
from function_tool import time_format_transform

import clickhouse_connect

connect_info = {
    'port': 8123,
    'host': '192.168.104.243',
    'username': 'default',
    'password': 'bwda2025',
    'database': 'lap'
}

client = clickhouse_connect.get_client(**connect_info)
column_list = ['bwd_create_time', 'zy_op_start_time', 'kz_op_type_name', 'kz_op_type_code', 'zy_op_master_account_name',
               'zy_op_person_name', 'zy_op_obj', 'kz_op_result', 'zy_resource_type', 'kz_resource_login_ip',
               'op_time']
insert_data = []
kz_op_result_list = ['0', '1']
zy_resource_type_list = ['0', '1', '2', '3', '4']
table = 'bwda_log_local'
for i in range(500000):
    bwd_create_time = datetime.datetime.now()
    zy_op_start_time = datetime.datetime.strftime(bwd_create_time, '%Y-%m-%d %H:%M:%S')
    kz_op_type_name = 'kz_op_type_name' + str(i).zfill(6)
    kz_op_type_code = 'kz_op_type_code' + str(i).zfill(6)
    zy_op_master_account_name = 'zy_op_master_account_name' + str(i).zfill(6)
    zy_op_person_name = 'zy_op_person_name' + str(i).zfill(6)
    zy_op_obj = 'zy_op_obj' + str(i).zfill(6)
    kz_op_result = random.choice(kz_op_result_list)
    zy_resource_type = random.choice(zy_resource_type_list)
    kz_resource_login_ip = '.'.join([str(random.randint(0, 255)) for _ in range(4)])
    op_time = datetime.datetime.strptime('2025-07-01 12:23:56', '%Y-%m-%d %H:%M:%S')
    insert_data.append(
        [bwd_create_time, zy_op_start_time, kz_op_type_name, kz_op_type_code, zy_op_master_account_name, zy_op_person_name,
         zy_op_obj, kz_op_result, zy_resource_type, kz_resource_login_ip, op_time])
client.insert(table, insert_data, column_names=column_list)
client.close()
